package com.fasteat.mall.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

	/**
	 * 创建队列
	 *
	 * @return
	 */
	@Bean
	public Queue queue() {
		return new Queue("advertisement.queue", true);
	}

	/**
	 * 创建交换机
	 *
	 * @return
	 */
	@Bean
	public FanoutExchange fanoutExchange() {
		return new FanoutExchange("advertisementExchange");
	}

	/**
	 * 绑定队列,参数名字要和bean名字一致
	 * @param queue
	 * @param fanoutExchange
	 * @return
	 */
	@Bean
	public Binding binding(Queue queue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(queue).to(fanoutExchange);
	}

}
